package com.example.builder.exp1;

public class ServiceProvider {
    // required
    private String address;
    private int port;

    // optional
    private String serviceName = "s1";
    private int maxConnection = 50;

    ServiceProvider(Builder builder) {
        this.address = builder.address;
        this.port = builder.port;
        this.serviceName = builder.serviceName;
        this.maxConnection = builder.maxConnection;
    }

    public static class Builder {
        private String address;
        private int port;
        private String serviceName;
        private int maxConnection;

        public Builder(String address, int port) {
            this.address = address;
            this.port = port;
        }

        public Builder serviceName(String sn) {
            serviceName = sn;
            return this;
        }

        public Builder maxConnection(int mc) {
            maxConnection = mc;
            return this;
        }

        public ServiceProvider build() {
            return new ServiceProvider(this);
        }
    }

    @Override
    public String toString() {
        return "ServiceProvider{" +
                "address='" + address + '\'' +
                ", port=" + port +
                ", serviceName='" + serviceName + '\'' +
                ", maxConnection=" + maxConnection +
                '}';
    }
}
